package services.managers;

import bbdd.Conexion;
import bean.BeanSession;
import models.usuario.Rol;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by juanky on 5/12/14.
 */
public class RolManager {
    public Rol getRol(BeanSession bean) {
        Rol rol = new Rol();
        Conexion cnx = new Conexion();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String select = "select descripcion from roles where id=?";
        try {
            ps = cnx.getConexion(select);
            ps.setInt(1, bean.getRolId());
            rs = ps.executeQuery();
            if (rs.next()) {
                rol.setId(bean.getRolId());
                rol.setDescripcion(rs.getString("descripcion"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            Conexion.close(cnx, ps, rs);
        }
        return rol;
    }
}
